package com.aspose.cells;

class zbup {
   private int a = 1048575;
   private int b = 16383;
   private Worksheet c;
   private String d = "Invalid formula in data validation settings.";

   zbup(Worksheet var1) {
      this.c = var1;
   }

   int a() {
      return this.a;
   }

   int b() {
      return this.b;
   }

   void a(Validation var1) {
      if (!var1.a()) {
         this.a = 1048575;
         this.b = 16383;
         int var2 = 0;

         for(int var3 = 0; var3 < var1.getAreaList().size(); ++var3) {
            Object var4 = var1.getAreaList().get(var3);
            if (var4 instanceof CellArea) {
               CellArea var5 = (CellArea)var4;
               if (var5.StartRow < this.a) {
                  this.a = var5.StartRow;
                  this.b = var5.StartColumn;
               }

               ++var2;
            }
         }

         if (var2 != 0) {
            Object var6 = null;
            if (var1.getType() != 0 && (var1.getFormula1() != null && !"".equals(var1.getFormula1()) || var1.d() != null)) {
               byte[] var7;
               if (var1.d() != null) {
                  var7 = var1.d();
               } else if (var1.getType() != 3 && var1.getFormula1().charAt(0) == '=') {
                  var7 = this.c.c().x().a(-1, var1.getFormula1(), this.a(), this.b(), 0, 32, true, false, false);
               } else {
                  var7 = this.a(var1, 1);
               }

               var1.a(var7);
            }

            byte[] var8 = null;
            if ((var1.getOperator() == 0 || var1.getOperator() == 7) && var1.getType() != 3 && var1.getType() != 7 && var1.getType() != 0) {
               if (var1.getType() == 7) {
                  if (var1.e() != null) {
                     var8 = var1.e();
                  }
               } else if (var1.e() != null) {
                  var8 = var1.e();
               } else if (var1.getFormula2() != null) {
                  if (var1.getFormula2().charAt(0) == '=') {
                     var8 = this.c.c().x().a(-1, var1.getFormula2(), this.a(), this.b(), 0, 64, true, false, false);
                  } else {
                     var8 = this.a(var1, 2);
                  }
               }

               var1.b(var8);
            }

         }
      }
   }

   private byte[] a(Validation var1, int var2) {
      String var3;
      if (var2 == 1) {
         var3 = var1.getFormula1();
      } else {
         var3 = var1.getFormula2();
      }

      if (var3 != null && !"=#REF!".equals(var3)) {
         if (var3 != null && !"".equals(var3)) {
            switch(var1.getType()) {
            case 1:
            case 2:
            case 6:
               return this.b(var3);
            case 3:
               return this.a(var3);
            case 4:
               return this.a(var3, false);
            case 5:
               return this.a(var3, true);
            default:
               return null;
            }
         } else {
            throw new CellsException(2, "You must enter data for validation criteria.");
         }
      } else {
         byte[] var4 = new byte[9];
         var4[0] = 43;
         return var4;
      }
   }

   private byte[] a(String var1) {
      Object var2 = null;
      byte[] var4;
      if (var1.charAt(0) == '=') {
         var4 = this.c.c().x().a(-1, var1, this.a(), this.b(), 0, 32, true, false, false);
      } else {
         var1 = var1.replace(',', '\u0000');
         byte[] var3 = Encoding.getUnicode().a(var1);
         var4 = new byte[3 + var3.length];
         var4[0] = 23;
         var4[1] = (byte)var1.length();
         var4[2] = 1;
         System.arraycopy(var3, 0, var4, 3, var3.length);
      }

      return var4;
   }

   private byte[] a(String var1, boolean var2) {
      if (var1 != null && var1.length() != 0) {
         Object var3 = null;
         if (var1.charAt(0) == '=') {
            return this.c.c().x().a(-1, var1, this.b(), this.b(), 0, 32, true, false, false);
         } else {
            try {
               DateTime var6 = DateTime.a(var1);
               double var4;
               if (var2) {
                  var4 = (double)(var6.getHour() * 3600 + var6.getMinute() * 60 + var6.getSecond()) / 86400.0D;
               } else {
                  var4 = CellsHelper.getDoubleFromDateTime(var6, this.c.c().n().getSettings().getDate1904());
               }

               byte[] var9;
               if (Math.abs(var4 - (double)((int)var4)) < Double.MIN_VALUE) {
                  int var7 = (int)var4;
                  if (var7 <= 65535 && var7 >= 0) {
                     var9 = new byte[]{30, 0, 0};
                     System.arraycopy(com.aspose.cells.b.a.zc.a(var7), 0, var9, 1, 2);
                  } else {
                     var9 = new byte[9];
                     var9[0] = 31;
                     System.arraycopy(com.aspose.cells.b.a.zc.a(var4), 0, var9, 1, 8);
                  }
               } else {
                  var9 = new byte[9];
                  var9[0] = 31;
                  System.arraycopy(com.aspose.cells.b.a.zc.a(var4), 0, var9, 1, 8);
               }

               return var9;
            } catch (Exception var8) {
               throw new CellsException(6, this.d);
            }
         }
      } else {
         return null;
      }
   }

   private byte[] b(String var1) {
      Object var2 = null;
      if (var1.charAt(0) == '=') {
         return this.c.c().x().a(-1, var1, this.a(), this.b(), 0, 64, true, false, false);
      } else if (!zapb.c(var1)) {
         throw new CellsException(2, this.d);
      } else {
         double var3 = com.aspose.cells.b.a.zn.a(var1, com.aspose.cells.b.a.c.za.b());
         byte[] var6;
         if (Math.abs(var3 - (double)((int)var3)) < Double.MIN_VALUE) {
            int var5 = (int)var3;
            if (var5 <= 65535 && var5 >= 0) {
               var6 = new byte[]{30, 0, 0};
               System.arraycopy(com.aspose.cells.b.a.zc.a(var5), 0, var6, 1, 2);
            } else {
               var6 = new byte[9];
               var6[0] = 31;
               System.arraycopy(com.aspose.cells.b.a.zc.a(var3), 0, var6, 1, 8);
            }
         } else {
            var6 = new byte[9];
            var6[0] = 31;
            System.arraycopy(com.aspose.cells.b.a.zc.a(var3), 0, var6, 1, 8);
         }

         return var6;
      }
   }
}
